package com.wanmait.employment.manageController;

import com.github.pagehelper.PageInfo;
import com.wanmait.employment.aop.LogInfo;
import com.wanmait.employment.entity.Admin;
import com.wanmait.employment.service.AdminService;
import com.wanmait.employment.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("manage/admin")
public class AdminConteroller {

    @Resource
    private AdminService adminService;
    @GetMapping("list")
    @ResponseBody
    public AjaxResult findAll(String name, int pageNum, int pageSize){
       PageInfo<Admin>adminPageInfo = adminService.findAll(name,pageNum,pageSize);
        return AjaxResult.success("success").put("adminPageInfo",adminPageInfo);

    }
    @PostMapping("update")
    public AjaxResult update(@RequestBody Admin admin){
        if(admin.getId()!=null) {
            Date date = new Date();
            admin.setCreateTime(date);
            adminService.update(admin);
        }else {
            adminService.insert(admin);
        }

        return AjaxResult.success("修改成功");
    }
    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        adminService.delete(id);
        return AjaxResult.success("删除成功");
    }

}
